<?php

namespace app\data\controller\api;

use app\data\service\ExpressService;
use app\data\service\GoodsService;
use think\admin\Controller;

/**
 * 产品数据接口
 * Class Goods
 * @package app\data\controller\api
 */
class Goods extends Controller
{
    /**
     * 获取分类数据
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getCate()
    {
        $this->success('获取分类成功', GoodsService::instance()->getCateDataByCompanyId(input('company_id')));
    }


    /**
     * 获取产品数据
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getGoods()
    {

        // 产品数据处理
        $cate_id = input('cate_id');


        $result = $this->app->db->name('ShopGoods')->where(['deleted' => 0, 'status' => 1, 'cate_id' => $cate_id])->order('sort desc,id desc')->select();

        $this->success('获取产品数据', $result);
    }

    /**
     *  获取配送区域
     */
    public function getRegion()
    {
        $this->success('获取区域成功', ExpressService::instance()->region(3, 1));
    }

}